x86: Define a new function gtsc_to_gtime()
authorKeir Fraser <keir@xen.org>
Wed, 15 Dec 2010 10:49:57 +0000 (10:49 +0000)
committerKeir Fraser <keir@xen.org>
Wed, 15 Dec 2010 10:49:57 +0000 (10:49 +0000)
Define it to do the transform from guest tsc to guest time.

Fix the typo in gtime_to_gtsc() definition.

Signed-off-by: Wei Gang <gang.wei@intel.com>
xen/arch/x86/time.c
xen/include/asm-x86/time.h

index d57a9cb518d4afe5f1b35a85a8188768cbc88e0a..0be33d97e254e0c177897a1dc466f9eafed68e37 100644 (file)
@@ -1634,11 +1634,20 @@ static void __init tsc_parse(const char *s)
 }
 custom_param("tsc", tsc_parse);
 
-u64 gtime_to_gtsc(struct domain *d, u64 tsc)
+u64 gtime_to_gtsc(struct domain *d, u64 time)
 {
     if ( !is_hvm_domain(d) )
-        tsc = max_t(s64, tsc - d->arch.vtsc_offset, 0);
-    return scale_delta(tsc, &d->arch.ns_to_vtsc);
+        time = max_t(s64, time - d->arch.vtsc_offset, 0);
+    return scale_delta(time, &d->arch.ns_to_vtsc);
+}
+
+u64 gtsc_to_gtime(struct domain *d, u64 tsc)
+{
+    u64 time = scale_delta(tsc, &d->arch.vtsc_to_ns);
+
+    if ( !is_hvm_domain(d) )
+        time += d->arch.vtsc_offset;
+    return time;
 }
 
 void pv_soft_rdtsc(struct vcpu *v, struct cpu_user_regs *regs, int rdtscp)
index 52f21dd4e9f40d61d511450b1169d2429b59fcaa..fa8236d5d6836aca6892f916d32a1763c3d10f7f 100644 (file)
@@ -59,7 +59,8 @@ uint64_t ns_to_acpi_pm_tick(uint64_t ns);
 uint64_t tsc_ticks2ns(uint64_t ticks);
 
 void pv_soft_rdtsc(struct vcpu *v, struct cpu_user_regs *regs, int rdtscp);
-u64 gtime_to_gtsc(struct domain *d, u64 tsc);
+u64 gtime_to_gtsc(struct domain *d, u64 time);
+u64 gtsc_to_gtime(struct domain *d, u64 tsc);
 
 void tsc_set_info(struct domain *d, uint32_t tsc_mode, uint64_t elapsed_nsec,
                   uint32_t gtsc_khz, uint32_t incarnation);